package com.example.timfinprototypeback.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;


public class netManger {
    public String rnnRun() {
        try {
            Process proc = Runtime.getRuntime().exec("conda activate base && python rnn.py");

            String myStr = new String(Files.readAllBytes(Paths.get("D:\\SeoriginalCode\\TimFinPrototypeBack\\src\\main\\java\\com\\example\\timfinprototypeback\\utils\\infer.json")));
            return myStr;
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        return null;
    }

    public byte[] TransRun() throws IOException {
        Process proc = Runtime.getRuntime().exec("conda activate base && python Trans.py");
        String pth = "D:\\SeoriginalCode\\TimFinPrototypeBack\\src\\main\\java\\com\\example\\timfinprototypeback\\utils\\infer.png";
        File file = new File(pth);
        FileInputStream inputStream = new FileInputStream(file);
        byte[] bytes = new byte[inputStream.available()];
        inputStream.read(bytes, 0, inputStream.available());
        return bytes;
    }

    public static void main(String[] args) {
        netManger my = new netManger();
        System.out.println(my.rnnRun());
        try{
            System.out.println(my.TransRun().toString());
        } catch (Exception e) {
            ;
        }
    }
}
